#include <stdio.h>
#define SIZE 100001

int
main ()
{
	int arr[SIZE], n, m, ni, mi; //frequencies, i's
	register int i;

	freopen("numbers.in", "r", stdin);
	freopen("numbers.out", "w", stdout);

	for (i=0;i<SIZE;++i)
		arr[i] = 0;

	while(scanf("%d", &n) == 1 && n != 0) {
		++arr[n-1];
	}

	n = ni = m = mi = 0;
	for (i=0; i< SIZE; ++i) {
		if (arr[i] > n) {
			m = n;
			mi = ni;
			n = arr[i];
			ni = i;
		} else if (arr[i] > m) {
			m = arr[i];
			mi = i;
		}
	}

	printf ("%d %d\n", ++ni, ++mi);
	return 0;
}
